unit uDM;

interface

uses
  SysUtils, Classes, WideStrings, DB, SqlExpr, FMTBcd, DBXpress;

type
  Tdm = class(TDataModule)
    MedicoPro: TSQLConnection;
    qryNextCod: TSQLQuery;
    qryNextCodMAX: TIntegerField;
  private
    { Private declarations }
  public
    function GetNextCod(Tabela, Campo:string):integer;
  end;

var
  dm: Tdm;

implementation

{$R *.dfm}

{ Tdm }

function Tdm.GetNextCod(Tabela, Campo: string): integer;
begin
    qryNextCod.CommandText := 'select max('+Campo+') from '+Tabela;
    qryNextCod.Open;
    result:=qryNextCodMax.AsInteger + 1;
    qryNextCod.close;
end;

end.
